#!/bin/bash
# 安装docker
# 卸载旧版本密钥
sudo apt-get remove docker docker-engine docker.io
# apt能使用https方式并且CA证书已安装
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# 添加Docker官方的gpg密钥
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 添加清华源
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 执行apt-update
sudo apt-get update
sudo apt-get install docker-ce -y
systemctl enable docker
# 部署kubectl，kubelet，kubeadm
# 源文件不存在
if [ ! -f "/etc/apt/sources.list.d/kubernetes.list" ]; then
    sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
    echo "deb  https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
    sudo apt update && apt-get install  kubelet kubeadm kubectl -y
    systemctl enable kubelet
fi
# 源文件已存在
if [ -f "/etc/apt/sources.list.d/kubernetes.list"  ]; then
    sudo rm -Rf /etc/apt/sources.list.d/kubernetes.list -y
    sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
    echo "deb  https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
    sudo apt update && apt-get install  kubelet kubeadm kubectl -y
    systemctl enable kubelet
fi